import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import argparse
import time

def parse_args():
    parser = argparse.ArgumentParser("")
    parser.add_argument("--input", "-i", default='/home/xiaoyf/data/HG002/R9.4/extract_part1_3.3.log', type=str,required=False)
    parser.add_argument("--output", "-o", default='/home/xiaoyf/data/HG002/R9.4/', type=str,required=False)
    return parser.parse_args()

# 读取TSV文件
args=parse_args()
df=[]
with open(args.input, 'r') as f:
    for line in f:
        words=line.strip().split('   ')
        try:
            df.append(float(words[0]))
        except:
            print(words[0])
            break

count_below_0_2 = sum(1 for value in df if value <= 0.2)
total_count = len(df)
percentage_below_0_2 = count_below_0_2 / total_count

count_below_0_0 = sum(1 for value in df if value == 0.0)
percentage_below_0_0 = count_below_0_0 / total_count
# 计算比例为0.8的分割点
sorted_data = sorted(df)
index_0_8 = int(0.8 * total_count)
quantile_0_8 = sorted_data[index_0_8]

print("0的比例：", percentage_below_0_0)
print("小于0.2的比例：", percentage_below_0_2)
print("比例为0.8的分割点：", quantile_0_8)


# 选择要绘制密度分布图的列
column_of_interest = 0  

# 绘制密度分布图
sns.kdeplot(df)
plt.xlabel('X Label')  
plt.ylabel('Density')  
plt.title('Density Plot')  
#plt.show()

plt.savefig(args.output+'density_plot.png')  
#plt.show()